$(document).ready(function(){
	var numUpl = new Array();
//	var picUrl = new Array();
	$("#commmentDetail button[pe='button']").each(function(){
		var uploadUl = $(this).parent().find("ul").attr("id");
		var uploadBtn = $(this).attr("id");
		var picUrl= "";
		var uploader = new plupload.Uploader({
			//对运行环境的检测
			runtimes : 'html5,flash,silverlight,html4',
			//设置选择文件的标签的id；
			browse_button : uploadBtn, 
			//后台处理的路径
			url : 'upload.do',
			//内置的脚本
			flash_swf_url : '../js/Moxie.swf',
			silverlight_xap_url : '../js/Moxie.xap',
			//图片的类型和图片的最大的容量
			filters : {
				max_file_size : '10mb',
				mime_types: [
					{title : "Image files", extensions : "jpg,gif,png"},
					{title : "Zip files", extensions : "zip"}
				],
				prevent_duplicates : true //不允许选取重复文件
			},
			
			//初始化图片上传
			init: {
				PostInit: function() {
					document.getElementById(uploadUl).innerHTML = '';

					document.getElementById(uploadBtn).onclick = function() {
						
						return false;
					};
				},
				BeforeUpload : function(up, file) {
					up.settings.url = encodeURI("./upload.do?" + "name="+ file.name+"&type="+file.type+"&size="+file.size);

				},
				//添加上传文件的操作
				FilesAdded: function(up, files) {
					var num = 0;
					//设置限制的图片数量
					for(i=0;i<numUpl.length;i++){
						alert(i+","+numUpl[i])
						num = num + numUpl[i];
					}
					var count=uploader.files.length; 
				    if(count>5){
				        alert("最多只能上传5张图片");
				        count = num;
				        up.files.length = num;
				        return false;
				    }else if(count==0){
				    	alert("没有要上传的文件"); 
				    	return false;
				    }else{
				    	plupload.each(files, function(file) { 
//		    				document.getElementById(uploadUl).innerHTML += "<li id='"+file.id+"'>"+file.type+"</td><td>"+file.name+"</td><td><button type='button' id='"+file.id+"btn' onclick=del('"+file.id+"')>删除</button><span></span></li>";
		    				document.getElementById(uploadUl).innerHTML += "<li id='"+file.id+"'><img id='uploadImg_"+file.id+"' name='uploadImg' src='"+file.name+"' width='50px' height='50px' /></li>";
				    	});
				    	numUpl.push(files.length);
				    	uploader.start(); 
				    	return false;
				    } 
				    
				},

				//上传的进度设置
				UploadProgress: function(up, file) {
//					document.getElementById(file.id).getElementsByTagName('span')[0].innerHTML=+ file.percent + "%";
				},
				
				//所有文件上传成功的操作
				UploadComplete : function(uploader, files) {
//					alert(files.length+"个文件上传成功");
				},
				//单个文件上传成功的操作
				FileUploaded : function(up, file,result) {
//					alert(file+"个文件999上传成功");
					var uploadImg = file.id;
					$("#uploadImg_"+uploadImg).attr("src", result.response);
					picUrl = picUrl + result.response + ",";
					
					var uploadInput = $("#"+uploadImg).parent().parent().find("input").attr("id");
					$("#"+uploadInput).val(picUrl);
//					alert("uploadInput==fff=>>///"+$("#"+uploadInput).val());
				},
				//上传时的错误处理
				Error: function(up, err) {
				}
			}
		});
		
		//上传组件初始化
		uploader.init();
		
	
	});
	
});